#include <stdio.h>
#include <limits.h>

#define N 100

void selection_sort(int input_array[], int array_length);

int main() {
    int input_array[N] = { 0 };
    char ch;
    int array_length = 0;

    printf("请输入一串整数，以空格隔开：");

    while ((scanf("%d", &input_array[array_length++])) != EOF && getchar() != '\n') ;
    
    selection_sort(input_array, array_length);

    printf("排序后的结果为：");
    for (int i = 0; i < array_length; i++)
        printf("%d ", input_array[i]);
    putchar('\n');

    return 0;
}

void selection_sort(int input_array[], int array_length) {
    int max = INT_MIN, max_index;

    if (array_length == 0) return;

    for (int i = 0; i < array_length; i++) {
        if (input_array[i] > max) {
            max = input_array[i];
            max_index = i;
        }
    }   

    input_array[max_index] = input_array[array_length - 1];
    input_array[array_length - 1] = max;

    selection_sort(input_array, array_length - 1);
}
